package net.zeus.sample.rabbitmq.exchange;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import net.zeus.sample.rabbitmq.utils.ConnectionUtils;

/**
 * 发送交换 订阅模式
 * @author Michael
 *
 */
public class ExchangeSender {

	public static void main(String[] args) throws Exception{
		Connection conn = ConnectionUtils.getConnection();
		
		Channel channel = conn.createChannel();

		/*
		 * 声明交换，分发类型为：
		 * fanout-不处理路由键
		 * direct-处理路由键
		 */
		channel.exchangeDeclare(ConnectionUtils.EXCHANGE_NAME, "fanout");
		
		String msg = "hello exchange text";
		
		channel.basicPublish(ConnectionUtils.EXCHANGE_NAME, "", null, msg.getBytes());
		
		System.out.println("send exchange msg:" + msg);
		
		channel.close();
		ConnectionUtils.closeConnection(conn);
	}

}
